package com.enlorenz.common.bankinfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 卡片工具
 * 
 * @author oyz
 * 
 */
public class BankInfoCardBinNewUtils {

	private static Map<String, BankCardNewInfo> cardMapping = new HashMap<String, BankCardNewInfo>();

	public static Map<String, BankCardNewInfo> getCardMapping() {
		return cardMapping;
	}

	public static void setCardMapping(Map<String, BankCardNewInfo> cardMapping) {
		BankInfoCardBinNewUtils.cardMapping = cardMapping;
	}

	/**
	 * 根据卡号判断是否是内卡
	 * 
	 * @param cardNo
	 * @return
	 */
	public static boolean isInnerCard(String cardNo) {
		if (null == cardMapping) {
			initCardMapping();
		}
		BankCardNewInfo bci = getBankCardInfo(cardNo);
		if (null != bci) {
			return true;
		}
		return false;
	}

	/**
	 * 根据卡号判断卡的类别
	 * 
	 * @param cardNo
	 * @return
	 */
	public static String getCardType(String cardNo) {
		if (null == cardMapping) {
			initCardMapping();
		}
		BankCardNewInfo bci = getBankCardInfo(cardNo);
		return bci.getCardType();
	}

	/**
	 * 通过卡号获取卡片信息
	 * 
	 * @param cardNo
	 * @return
	 */
	public static BankCardNewInfo getBankCardInfo(String cardNo) {
		if (null == cardMapping) {
			initCardMapping();
		}
		String prefix = null;
		BankCardNewInfo bci = new BankCardNewInfo();
		for (int i = 11; i <= 11; i--) {
			prefix = cardNo.substring(0, i);
			bci = cardMapping.get(prefix);
			if (null != bci) {
				return bci;
			}
		}
		return bci;
	}

	private static void initCardMapping() {
		getCardMapping();
	}

}
